package com.to8to.kitt.strategy;

import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

public class RoundRobinStrategy<T> implements SelectorStrategy<T>
{
    private final AtomicInteger index = new AtomicInteger(0);

	@Override
	public T select(List<T> instances) {
		if ( instances.size() == 0 )
			return null;
        int thisIndex = Math.abs(index.getAndIncrement());
        return instances.get(thisIndex % instances.size());
	}
}
